package com.palazzisoft.balonpie.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class LoginController {

    
    @RequestMapping(value = "/login.htm")
    public String login() {
        return "/login/login";
    }

    @RequestMapping(value = "/authenticate.htm")    
    public String authenticate(@RequestParam("username") String username, @RequestParam("password") String password) {
        return "/main/main";
    }
    
    @RequestMapping(value = "/logout.htm")    
    public String logout() {
        return "/main/main";
    }    
    
    @RequestMapping(value = "/afterLogin.htm")
    public String goToDefaultAfterLogin(HttpServletRequest request) {
        if (request.isUserInRole("ROLE_ADMIN")) {
            return "/admin/index";
        }
        
        return "/main/main";
    }
}
